//
//  VideoViewController.m
//  Shanghai Cuisine
//
//  Created by iOS Two on 14/12/16.
//  Copyright (c) 2014年 iOS Two. All rights reserved.
//

#import "VideoViewController.h"
#import "AppDelegate.h"

@interface VideoViewController ()

@end

@implementation VideoViewController
-(void)viewWillAppear:(BOOL)animated {// 开始播放
    [MobClick beginLogPageView:@"VideoViewController"];
    
    AppDelegate * appDelegate = [[UIApplication sharedApplication] delegate];
    
    appDelegate.isFull = YES;
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        
        SEL selector = NSSelectorFromString(@"setOrientation:");
        
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        
        [invocation setSelector:selector];
        
        [invocation setTarget:[UIDevice currentDevice]];
        
        int val =UIDeviceOrientationLandscapeRight|UIDeviceOrientationLandscapeLeft;
        
        [invocation setArgument:&val atIndex:2];
        
        [invocation invoke];
    }
}

-(void)viewWillDisappear:(BOOL)animated {//完成播放
    [MobClick endLogPageView:@"VideoViewController"];
    
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    
    appDelegate.isFull =NO;
    
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        
        SEL selector = NSSelectorFromString(@"setOrientation:");
        
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        
        [invocation setSelector:selector];
        
        [invocation setTarget:[UIDevice currentDevice]];
        
        int val =UIInterfaceOrientationPortrait;
        
        [invocation setArgument:&val atIndex:2];
        
        [invocation invoke];
    }
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatController];
    UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshData)];
    self.navigationItem.rightBarButtonItem = right;
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
    titleLabel.text = _videoName;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.textColor = [UIColor colorWithRed:0.97 green:0.69 blue:0.17 alpha:1];
    self.navigationItem.titleView = titleLabel;
    // Do any additional setup after loading the view.
}
-(void)creatController {
    _web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kwidth, kHeight - stateHight.size.height - navHight)];
    _web.delegate = self;
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:_videoLink]];
    [_web loadRequest:request];
    _web.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_web];
}
-(void)refreshData {
    [_web reload];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
//    [self showIndeterminateProgress];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
//    [HUD hide:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
